package com.example.util.redis;/**
 * @author wangXiao
 */

import com.example.util.listener.WxTestRedisMessageListener;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.listener.PatternTopic;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.springframework.data.redis.listener.adapter.MessageListenerAdapter;

/**
 * @Description: TODO
 * @Author wangXiao
 * @Date 2024/9/30 
 **/
@Slf4j
@Configuration
public class RedisMessageListener {

    @Bean
    public RedisMessageListenerContainer container(RedisConnectionFactory connectionFactory,
                                                   MessageListenerAdapter wxtestListenerAdapter) {
        RedisMessageListenerContainer container = new RedisMessageListenerContainer();
        container.setConnectionFactory(connectionFactory);
        log.info("wx自测redis监听");
        container.addMessageListener(wxtestListenerAdapter, new PatternTopic("wx_test"));
        return container;
    }

    @Bean
    public MessageListenerAdapter wxtestListenerAdapter(WxTestRedisMessageListener wxTestRedisMessageListener) {
        return new MessageListenerAdapter(wxTestRedisMessageListener);
    }
}
